// const { city_name } = require("../../../public/config/config");

// console.log("process.env.NODE_ENV: ", process.env.NODE_ENV);
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (elt) {
    var len = this.length >>> 0;
    var from = Number(arguments[1]) || 0;
    from = from < 0 ? Math.ceil(from) : Math.floor(from);
    if (from < 0) from += len;
    for (; from < len; from++) {
      if (from in this && this[from] === elt) return from;
    }
    return -1;
  };
}
var baseUrl = "/wycms-api";
var zhibanDetail = {};

function handleResponse(res) {
  zhibanDetail = res.data;
  console.log("zhibanDetail: ", zhibanDetail);

  var s = "";
  if (["dt", "sz"].indexOf(city_name) > -1) {
    s += "<span>";
    s += `<p class="title">值班提示</p>
      <p class="desc">
        <span class="left">带班领导：</span>
        <span class="right">

          <span class="leader1"> ${zhibanDetail.leader1} </span>&nbsp;&nbsp;

          `;
    if (zhibanDetail.leader2) {
      s += `<span class="leader2"> ${zhibanDetail.leader2}</span>`;
    }
    s += ` </span></p>`;

    if (["sz"].indexOf(city_name) > -1) {
      s += `<p class="desc">
        <span class="left">备班人员：</span>
        <span class="right">
          <span class="dutypeople1">${zhibanDetail.dutypeople1}</span>&nbsp;&nbsp;
      `;
      //  <span class="dutypeople2">${zhibanDetail.dutypeople2}</span>
      //   </span>
      // </p>
      // <p class="desc">
      //   <span class="left">值班人员：</span>
      //   <span class="right">
      //     <span class="weekdaypeople1">${zhibanDetail.weekdaypeople1}</span>&nbsp;&nbsp;
      //     <span class="weekdaypeople2">${zhibanDetail.weekdaypeople2}</span>
      //   </span>
      // </p>
      if (zhibanDetail.dutypeople2) {
        s += `
        <span class="dutypeople2">${zhibanDetail.dutypeople2}</span>
        `;
      }
      s += `</span>
      </p>
      `;
    }

    s += `
      <p class="desc">
        <span class="left">值班人员：</span>
        <span class="right">
          <span class="weekdaypeople1">${zhibanDetail.weekdaypeople1}</span>&nbsp;&nbsp;`;
    if (zhibanDetail.weekdaypeople2) {
      s += `<span class="weekdaypeople2">${zhibanDetail.weekdaypeople2}</span>`;
    }
    s += `</span>
      </p>`;
    s += "</span>";
  } else if (["yc"].indexOf(city_name) > -1) {
    s += `<span>
      <marquee scrollamount="2">
        <span class="name"> ${zhibanDetail.dutypeople1} </span>
        <span class="phone"> 电话：${zhibanDetail.phone} </span>
        <span class="tel"> 手机号：${zhibanDetail.tel} </span>
      </marquee>
    </span>  `;
  }
  $("#app").append(s);
}

function getZhiban(name) {
  var query = getQuery();
  console.log("query: ", query);
  if (["yc"].indexOf(city_name) > -1) {
    $.ajax({
      url: baseUrl + "/customize/duty/indexYcMini",
      method: "post",
      headers: { "content-type": "application/x-www-form-urlencoded" },
      xhrFields: { withCredentials: false },
      data: { siteId: query.siteId },
      success: handleResponse,
    });
  } else {
    $.ajax({
      url: baseUrl + "/customize/duty/index",
      method: "post",
      headers: { "content-type": "application/x-www-form-urlencoded" },
      xhrFields: { withCredentials: false },
      data: { siteId: query.siteId },
      success: handleResponse,
    });
  }
}

getZhiban();
